<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    
    <title>使用 hugo 写博客 | jouyouyun&#39;s blog</title>
    <meta name="viewport" content="width=device-width,minimum-scale=1">
    <meta name="description" content="hugo 是由 Go 语言实现的静态网站生成器, 简单、易用、高效、易扩展、快速部署。
安装
到 Release 下载对应系统的二进制文件压缩包, 然后解压, 并把得到的二进制复制到 Path 中.
简单使用
创建一个站点
使用命令 hugo new site &lt;dir&gt; 来创建站点, 创建后的结构如下:">
    <meta name="generator" content="Hugo 0.105.0">
    
    
    
    
      <meta name="robots" content="noindex, nofollow">
    

    
<link rel="stylesheet" href="/ananke/css/main.min.css" >



    
    
    
      

    

    
    
    <meta property="og:title" content="使用 hugo 写博客" />
<meta property="og:description" content="hugo 是由 Go 语言实现的静态网站生成器, 简单、易用、高效、易扩展、快速部署。
安装
到 Release 下载对应系统的二进制文件压缩包, 然后解压, 并把得到的二进制复制到 Path 中.
简单使用
创建一个站点
使用命令 hugo new site &lt;dir&gt; 来创建站点, 创建后的结构如下:" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://jouyouyun.github.io/post/hugo-github/" /><meta property="article:section" content="post" />
<meta property="article:published_time" content="2019-02-02T17:31:21+08:00" />
<meta property="article:modified_time" content="2019-02-12T14:22:14+08:00" />

<meta itemprop="name" content="使用 hugo 写博客">
<meta itemprop="description" content="hugo 是由 Go 语言实现的静态网站生成器, 简单、易用、高效、易扩展、快速部署。
安装
到 Release 下载对应系统的二进制文件压缩包, 然后解压, 并把得到的二进制复制到 Path 中.
简单使用
创建一个站点
使用命令 hugo new site &lt;dir&gt; 来创建站点, 创建后的结构如下:"><meta itemprop="datePublished" content="2019-02-02T17:31:21+08:00" />
<meta itemprop="dateModified" content="2019-02-12T14:22:14+08:00" />
<meta itemprop="wordCount" content="211">
<meta itemprop="keywords" content="hugo,even," /><meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="使用 hugo 写博客"/>
<meta name="twitter:description" content="hugo 是由 Go 语言实现的静态网站生成器, 简单、易用、高效、易扩展、快速部署。
安装
到 Release 下载对应系统的二进制文件压缩包, 然后解压, 并把得到的二进制复制到 Path 中.
简单使用
创建一个站点
使用命令 hugo new site &lt;dir&gt; 来创建站点, 创建后的结构如下:"/>

	
  </head>

  <body class="ma0 avenir bg-near-white">

    
   
  

  <header>
    <div class="bg-black">
      <nav class="pv3 ph3 ph4-ns" role="navigation">
  <div class="flex-l justify-between items-center center">
    <a href="/" class="f3 fw2 hover-white no-underline white-90 dib">
      
        jouyouyun&#39;s blog
      
    </a>
    <div class="flex-l items-center">
      

      
        <ul class="pl0 mr3">
          
          <li class="list f5 f4-ns fw4 dib pr3">
            <a class="hover-white no-underline white-90" href="/post/" title="Archives 页">
              Archives
            </a>
          </li>
          
          <li class="list f5 f4-ns fw4 dib pr3">
            <a class="hover-white no-underline white-90" href="/tags/" title="Tags 页">
              Tags
            </a>
          </li>
          
          <li class="list f5 f4-ns fw4 dib pr3">
            <a class="hover-white no-underline white-90" href="/categories/" title="Categories 页">
              Categories
            </a>
          </li>
          
        </ul>
      
      
<div class="ananke-socials">
  
    <a href="https://github.com/jouyouyun" target="_blank" class="github ananke-social-link link-transition stackoverflow link dib z-999 pt3 pt0-l mr1" title="GitHub link" rel="noopener" aria-label="follow on GitHub——Opens in a new window">
      
        <span class="icon"><svg style="enable-background:new 0 0 512 512;" version="1.1" viewBox="0 0 512 512"  xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" >
  <path d="M256,32C132.3,32,32,134.8,32,261.7c0,101.5,64.2,187.5,153.2,217.9c11.2,2.1,15.3-5,15.3-11.1   c0-5.5-0.2-19.9-0.3-39.1c-62.3,13.9-75.5-30.8-75.5-30.8c-10.2-26.5-24.9-33.6-24.9-33.6c-20.3-14.3,1.5-14,1.5-14   c22.5,1.6,34.3,23.7,34.3,23.7c20,35.1,52.4,25,65.2,19.1c2-14.8,7.8-25,14.2-30.7c-49.7-5.8-102-25.5-102-113.5   c0-25.1,8.7-45.6,23-61.6c-2.3-5.8-10-29.2,2.2-60.8c0,0,18.8-6.2,61.6,23.5c17.9-5.1,37-7.6,56.1-7.7c19,0.1,38.2,2.6,56.1,7.7   c42.8-29.7,61.5-23.5,61.5-23.5c12.2,31.6,4.5,55,2.2,60.8c14.3,16.1,23,36.6,23,61.6c0,88.2-52.4,107.6-102.3,113.3   c8,7.1,15.2,21.1,15.2,42.5c0,30.7-0.3,55.5-0.3,63c0,6.1,4,13.3,15.4,11C415.9,449.1,480,363.1,480,261.7   C480,134.8,379.7,32,256,32z"/>
</svg>
</span>
      
<span class="new-window"><svg  height="8px"  style="enable-background:new 0 0 1000 1000;" version="1.1" viewBox="0 0 1000 1000"  xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" >
<path d="M598 128h298v298h-86v-152l-418 418-60-60 418-418h-152v-86zM810 810v-298h86v298c0 46-40 86-86 86h-596c-48 0-86-40-86-86v-596c0-46 38-86 86-86h298v86h-298v596h596z" style="fill-rule:evenodd;clip-rule:evenodd;"/>
</svg>
</span></a>
  
</div>

    </div>
  </div>
</nav>

    </div>
  </header>



    <main class="pb7" role="main">
      
  
  <article class="flex-l flex-wrap justify-between mw8 center ph3">
    <header class="mt4 w-100">
      <aside class="instapaper_ignoref b helvetica tracked">
          
        POSTS
      </aside>
      










  <div id="sharing" class="mt3 ananke-socials">
    
  </div>


      <h1 class="f1 athelas mt3 mb1">使用 hugo 写博客</h1>
      
      <p class="tracked">
         <strong>jouyouyun</strong>
      </p>
      
      
      
      <time class="f6 mv4 dib tracked" datetime="2019-02-02T17:31:21+08:00">二月 2, 2019</time>
      

      
      
    </header>
    <div class="nested-copy-line-height lh-copy serif f4 nested-links mid-gray pr4-l w-two-thirds-l"><p><a href="https://github.com/gohugoio/hugo">hugo</a> 是由 <code>Go</code> 语言实现的静态网站生成器, 简单、易用、高效、易扩展、快速部署。</p>
<h2 id="安装">安装</h2>
<p>到 <a href="https://github.com/gohugoio/hugo/releases">Release</a> 下载对应系统的二进制文件压缩包, 然后解压, 并把得到的二进制复制到 <code>Path</code> 中.</p>
<h2 id="简单使用">简单使用</h2>
<h3 id="创建一个站点">创建一个站点</h3>
<p>使用命令 <code>hugo new site &lt;dir&gt;</code> 来创建站点, 创建后的结构如下:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span>.
</span></span><span style="display:flex;"><span>├── archetypes
</span></span><span style="display:flex;"><span>│   └── default.md
</span></span><span style="display:flex;"><span>├── config.toml
</span></span><span style="display:flex;"><span>├── content
</span></span><span style="display:flex;"><span>├── data
</span></span><span style="display:flex;"><span>├── layouts
</span></span><span style="display:flex;"><span>├── static
</span></span><span style="display:flex;"><span>└── themes
</span></span></code></pre></div><p>各目录的简单说明如下, 具体请见 <a href="https://gohugo.io/getting-started/directory-structure/">Directory Structure Explained</a> :</p>
<ul>
<li><strong>archetypes:</strong> 预定义的文章模板</li>
<li><strong>config.toml:</strong> 站点的配置文件</li>
<li><strong>content:</strong> 文章存放的目录</li>
<li><strong>data:</strong> 生成 <code>website</code> 时用到的配置文件目录</li>
<li><strong>layouts:</strong> 页面 <code>html</code> 的模板目录</li>
<li><strong>static:</strong> 存放静态文件, 如 <code>css</code>, <code>js</code> 和图片等</li>
<li><strong>themes:</strong> 主题存放目录</li>
</ul>
<h3 id="配置主题">配置主题</h3>
<p>主题可以直接复制到 <code>themes</code> 目录下, 也可以通过 <code>git submodule</code> 的方式放在 <code>themes</code>, 这里使用后者, 因为便于管理.</p>
<p>这里使用 <code>even</code> 主题, 安装如下:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span>git submodule add https://github.com/olOwOlo/hugo-theme-even.git themes/even
</span></span></code></pre></div><p>然后将 <code>themes/even/config.toml</code> 替换掉站点的.</p>
<p>子模块的一些常用操作:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span><span style="color:#75715e"># 添加子模块</span>
</span></span><span style="display:flex;"><span>git submodule add https://github.com/username/gitname.git gitname
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 递归克隆带有子模块的仓库</span>
</span></span><span style="display:flex;"><span>git clone https://github.com/username/yourblog.git yourblog --recursive
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 上面递归克隆的命令等同于下面几行代码</span>
</span></span><span style="display:flex;"><span>git clone https://github.com/username/yourblog.git yourblog
</span></span><span style="display:flex;"><span>git submodule init    <span style="color:#75715e"># 初始化子模块</span>
</span></span><span style="display:flex;"><span>git submodule update  <span style="color:#75715e"># 更新子模块</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 此处要注意，如果你需要对子模块做出更改，需要创建或检出一个分支，Git默认不在任何分支上</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 删除子模块</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 逆初始化模块，其中{MOD_NAME}为模块目录，执行后可发现模块目录被清空</span>
</span></span><span style="display:flex;"><span>git submodule deinit <span style="color:#f92672">{</span>MOD_NAME<span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 删除.gitmodules中记录的模块信息（--cached选项清除.git/modules中的缓存）</span>
</span></span><span style="display:flex;"><span>git rm --cached <span style="color:#f92672">{</span>MOD_NAME<span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 提交更改到代码库，可观察到&#39;.gitmodules&#39;内容发生变更</span>
</span></span><span style="display:flex;"><span>git commit -am <span style="color:#e6db74">&#34;Remove a submodule.&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 修改某子模块的远程库(url)</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 首先手动修改&#39;.gitmodules&#39;文件中对应模块的”url“属性</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 更新子模块的 url</span>
</span></span><span style="display:flex;"><span>git submodule sync
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 提交变更</span>
</span></span><span style="display:flex;"><span>git commit -am <span style="color:#e6db74">&#34;Update submodule url.&#34;</span>
</span></span></code></pre></div><h3 id="配置">配置</h3>
<p>编辑 <code>config.toml</code> 文件来配置, 具体看文件里的注释.</p>
<h3 id="新建文章">新建文章</h3>
<p><code>hugo new post/&lt;filename.md&gt;</code> 将会在 <code>content/post/</code> 创建文件 <code>filename.md</code>, 然后编辑这个文件来写文章.</p>
<p>文章写完后去掉文件中的 <code>draft=true</code>, 不然生成到 <code>public</code> 中.</p>
<h3 id="预览">预览</h3>
<p>执行 <code>hugo server</code> 就可以按照给定的地址去看刚写的文章了.</p>
<h3 id="生成">生成</h3>
<p>使用 <code>hugo</code> 命令生成站点到 <code>public</code>, 然后将 <code>public</code> 发布.</p>
<h2 id="自动发布到-github-page">自动发布到 <code>Github Page</code></h2>
<p>在 <code>github</code> 创建一个以 <code>&lt;username&gt;.github.io</code> 命名的仓库, 然后将 <code>public</code> 中的文件 <code>push</code> 到刚才的 <code>repo</code> 中.</p><ul class="pa0">
  
   <li class="list di">
     <a href="/tags/hugo" class="link f5 grow no-underline br-pill ba ph3 pv2 mb2 dib black sans-serif">hugo</a>
   </li>
  
   <li class="list di">
     <a href="/tags/even" class="link f5 grow no-underline br-pill ba ph3 pv2 mb2 dib black sans-serif">even</a>
   </li>
  
</ul>
<div class="mt6 instapaper_ignoref">
      
      
      </div>
    </div>

    <aside class="w-30-l mt6-l">




</aside>

  </article>

    </main>
    <footer class="bg-black bottom-0 w-100 pa3" role="contentinfo">
  <div class="flex justify-between">
  <a class="f4 fw4 hover-white no-underline white-70 dn dib-ns pv2 ph3" href="https://jouyouyun.github.io" >
    &copy;  jouyouyun 2023 
  </a>
    <div>
<div class="ananke-socials">
  
    <a href="https://github.com/jouyouyun" target="_blank" class="github ananke-social-link link-transition stackoverflow link dib z-999 pt3 pt0-l mr1" title="GitHub link" rel="noopener" aria-label="follow on GitHub——Opens in a new window">
      
        <span class="icon"><svg style="enable-background:new 0 0 512 512;" version="1.1" viewBox="0 0 512 512"  xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" >
  <path d="M256,32C132.3,32,32,134.8,32,261.7c0,101.5,64.2,187.5,153.2,217.9c11.2,2.1,15.3-5,15.3-11.1   c0-5.5-0.2-19.9-0.3-39.1c-62.3,13.9-75.5-30.8-75.5-30.8c-10.2-26.5-24.9-33.6-24.9-33.6c-20.3-14.3,1.5-14,1.5-14   c22.5,1.6,34.3,23.7,34.3,23.7c20,35.1,52.4,25,65.2,19.1c2-14.8,7.8-25,14.2-30.7c-49.7-5.8-102-25.5-102-113.5   c0-25.1,8.7-45.6,23-61.6c-2.3-5.8-10-29.2,2.2-60.8c0,0,18.8-6.2,61.6,23.5c17.9-5.1,37-7.6,56.1-7.7c19,0.1,38.2,2.6,56.1,7.7   c42.8-29.7,61.5-23.5,61.5-23.5c12.2,31.6,4.5,55,2.2,60.8c14.3,16.1,23,36.6,23,61.6c0,88.2-52.4,107.6-102.3,113.3   c8,7.1,15.2,21.1,15.2,42.5c0,30.7-0.3,55.5-0.3,63c0,6.1,4,13.3,15.4,11C415.9,449.1,480,363.1,480,261.7   C480,134.8,379.7,32,256,32z"/>
</svg>
</span>
      
<span class="new-window"><svg  height="8px"  style="enable-background:new 0 0 1000 1000;" version="1.1" viewBox="0 0 1000 1000"  xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" >
<path d="M598 128h298v298h-86v-152l-418 418-60-60 418-418h-152v-86zM810 810v-298h86v298c0 46-40 86-86 86h-596c-48 0-86-40-86-86v-596c0-46 38-86 86-86h298v86h-298v596h596z" style="fill-rule:evenodd;clip-rule:evenodd;"/>
</svg>
</span></a>
  
</div>
</div>
  </div>
</footer>

  </body>
</html>
